/**
 * json配置举例，更多配置请看 IConfigSchema
 * @author luguoxiang
 * @date 2022/7/5
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
import { IConfigSchema, jsonFormat, LgBizSelect, LgBizSelectProps } from '@/soar';
import userApi from '@/pages/auth/user/api';

const fieldList: IConfigSchema<any>[] = [
  {
    field: 'userId',
    label: '用户',
    dataType: 'string',
    table: {
      colKey: 'userIdName',
      width: 120,
    },
    detail: {
      field: 'userIdName',
    },
    search: {
      component: LgBizSelect,
      componentProps: {
        data: userApi.query,
        valueField: 'id',
        labelField: '${nickname}(${username})',
        search: 'nickname|username',
      } as LgBizSelectProps,
    },
  },
  {
    field: 'operate',
    label: '操作',
    dataType: 'string',
    table: {
      ellipsis: true,
    },
  },
  {
    field: 'data',
    label: '数据',
    dataType: 'string',
    table: {
      ellipsis: true,
    },
    detail: {
      order: 101,
      slots: 'data',
      colProps: {
        style: '--lg-grid-min: 3',
      },
      formatter(data: any, value: any): string {
        try {
          return jsonFormat(JSON.parse(value), { wrap: '<br>', padding: '&nbsp;&nbsp;&nbsp;&nbsp;' });
        } catch (e) {
          return value;
        }
      },
    },
  },
  {
    field: 'path',
    label: '接口路径',
    dataType: 'string',
    table: {
      ellipsis: true,
    },
  },
  {
    field: 'datetime',
    label: '操作时间',
    dataType: 'datetime',
    table: {
      width: 150,
    },
  },
  {
    field: 'userIp',
    label: 'IP',
    dataType: 'string',
    table: {
      width: 135,
    },
  },
  {
    field: 'deviceType',
    label: '设备',
    dataType: 'enum',
    params: {
      COMPUTER: 'PC端',
      MOBILE: '移动端',
      TABLET: '平板端',
      GAME_CONSOLE: '游戏端',
      DMR: 'DMR',
      WEARABLE: '可穿戴端',
      UNKNOWN: '未知',
    },
    table: {
      width: 90,
    },
  },
  {
    field: 'system',
    label: '用户系统',
    dataType: 'string',
    table: {
      width: 120,
      ellipsis: true,
    },
  },
  {
    field: 'browser',
    label: '用户浏览器',
    dataType: 'string',
    table: {
      width: 120,
      ellipsis: true,
    },
  },
  {
    field: 'dataType',
    label: '数据类型',
    dataType: 'string',
    table: false,
    search: false,
  },
  {
    field: 'dataId',
    label: '数据id',
    dataType: 'string',
    table: false,
    search: false,
    detail: {
      colProps: {
        style: 'max-width: 100%',
      },
    },
  },
];

export default fieldList;
